package cn.tedu.zhwy.cardealer.service.impl;

import cn.tedu.zhwy.cardealer.mapper.CarportMapper;
import cn.tedu.zhwy.cardealer.pojo.dto.CarportQuery;
import cn.tedu.zhwy.cardealer.pojo.dto.CarportSaveParam;
import cn.tedu.zhwy.cardealer.pojo.entity.Carport;
import cn.tedu.zhwy.cardealer.pojo.vo.CarportVO;
import cn.tedu.zhwy.cardealer.service.CarportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CarportServiceImpl implements CarportService {

    @Autowired
    CarportMapper carportMapper;
    @Override
    public List<CarportVO> selectCarport(CarportQuery carportQuery) {
        log.debug("查询车位信息: carportQuery={}", carportQuery);
        List<CarportVO> list = carportMapper.selectCarport(carportQuery);
        return list;
    }

    @Override
    public void saveCarport(CarportSaveParam carportSaveParam) {
        log.debug("保存车位信息: carportSaveParam={}", carportSaveParam);
        Carport carport=new Carport();
        BeanUtils.copyProperties(carportSaveParam,carport);
        if (carport.getPid()==null){
            carportMapper.insert(carport);
        }else {
            carportMapper.update(carport);
        }
    }
    @Override
    public void deleteCarport(Long pid) {
        log.debug("删除车位信息: id={}", pid);
        carportMapper.deleteCarport(pid);
    }
}
